Mu |
Phi |
Nu |
Alpha |
Omega |
Delta |
CCAC2
CCAC local page
Times New Roman font
Arial Font Face
Playbill Font Face
<®>
- Top Cars USA
- Ford
- Toyota?!
- Chevy
/*
Towers of Hanoi
Kenneth L Moore
May 20, 2003
*/
#include <stdio.h>
#include
int moves;
void hanoi(int num, int src, int tmp, int dest){
if(num==0)return;// done
// move the stack on top of the big disk to tmp
hanoi(num-1 , src, dest, tmp);
// move the big disk to the target
printf("from %d to %d\n",src, tmp);
moves++;
// move the stack that was on top of the big disk
// back from the temp to the target
hanoi(num-1, dest, tmp, src);
}
void main(){
int numd;
int go=1;
while(go){
moves=0;
printf("enter number of disks\n");
scanf("%d",&numd);
printf("source 1 target 2 temporary 3\n");
hanoi(numd, 1, 2, 3);
printf("2 to the %d power = %g\n",numd,pow(2,numd));
printf("Number of moves %d\n",moves);
printf("\n Continue? (1=yes 0=no)\n");
scanf("%d",&go);
}
}